<?php

class MidiaHelper extends AppHelper {

    public $helpers = array('Html', 'Form');

    public function markitup($field, $options = array()) {
        $this->Html->script('/midias/latest/markitup/jquery.markitup.js', array('block' => 'script'));
        $this->Html->script('/midias/latest/markitup/sets/html/set.js', array('block' => 'script'));
        $this->Html->script('/midias/latest/markitup/markitup.js', array('block' => 'script'));
        $this->Html->css('/midias/latest/markitup/skins/markitup/style.css', null, array('block' => 'css'));
        $this->Html->css('/midias/latest/markitup/sets/html/style.css', null, array('block' => 'css'));
        return $this->textarea($field, 'markitup', $options);
    }

    public function redactor($field, $options = array()) {
        $this->Html->script('/midias/js/redactor/redactor.min.js', array('block' => 'script'));
        $this->Html->script('/midias/js/redactor/pt_br.js', array('block' => 'script'));
        $this->Html->script('/midias/js/redactor/redactor.extra.js', array('block' => 'script'));
        $this->Html->css('/midias/js/redactor/redactor.css', null, array('block' => 'css'));
        return $this->textarea($field, 'redactor', $options);
    }

    public function textarea($field, $editor = false, $options = array()) {
        $options = array_merge(array('label' => false, 'style' => 'width:100%;height:500px', 'row' => 160, 'type' => 'textarea', 'class' => "wysiwyg $editor"), $options);
        $html = $this->Form->input($field, $options);
        $html .= '<input type="hidden" id="midia_upload" value="' . $this->Html->url('/midias/midias/midia_upload/') . '">';
        $html .= '<input type="hidden" id="file_upload" value="' . $this->Html->url('/midias/midias/file_upload/') . '">';
        $html .= '<input type="hidden" id="lista_upload" value="' . $this->Html->url('/midias/midias/lista_upload/') . '">';
        return $html;
    }

}
